/** File: 	MyMenuBar.java
 *  Author:	Christopher Hayes
 *	Date:	Oct 15, 2009
 * 	Class:  CMSC 341
 *	Section	0201
 * 
 */
package cx3k.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

/**
 * @author chris
 *
 */
public class MyMenuBar extends JMenuBar {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JMenu jmFile, jmEdit, jmHelp, jmSchedule;
	private JMenuItem jmiNew, jmiSave, jmiQuit, jmiLoad, jmiConnect, jmiOptions, jmiGenerate, jmiNewSchedule, jmiAbout;
	private FileFrame fileframe;
	private Scheduler scheduler;
	private menuListener ML;

	public MyMenuBar(Scheduler s)  {
		this.scheduler = s;
		this.ML = new menuListener();
		jmFile = new JMenu("File");
		jmiNew = new JMenuItem("New");
		jmiSave = new JMenuItem("Save");
		jmiSave.addActionListener(ML);
		jmiQuit = new JMenuItem("Quit");
		jmiQuit.addActionListener(ML);
		jmiLoad = new JMenuItem("Load");
		jmiLoad.addActionListener(ML);
		jmiConnect = new JMenuItem("Connect");
		
		jmEdit = new JMenu("Edit");
		jmiOptions = new JMenuItem("Options");
		jmiOptions.addActionListener(ML);
		
		jmHelp = new JMenu("Help");
		jmiAbout = new JMenuItem("About CX3K");
		jmiAbout.addActionListener(ML);
		
		jmSchedule = new JMenu("Schedule");
		jmiGenerate = new JMenuItem("Generate");
		jmiNewSchedule = new JMenuItem("New Schedule");
		
		jmFile.add(jmiNew);
		jmFile.add(jmiLoad);
		jmFile.add(jmiSave);
		jmFile.add(jmiConnect);
		jmFile.add(jmiQuit);
		
		jmEdit.add(jmiOptions);
		
		jmHelp.add(jmiAbout);
		
		jmSchedule.add(jmiGenerate);
		jmSchedule.add(jmiNewSchedule);
		
		this.add(jmFile);
		//this.add(jmEdit);
		this.add(jmSchedule);
		this.add(jmHelp);
		
		this.fileframe = new FileFrame();
		
	}
	
	private class menuListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent ae) {
			// TODO Auto-generated method stub
			
			if (ae.getSource() == jmiAbout) {
				HelpFrame help = new HelpFrame();
			}
			else if(ae.getSource() == jmiNew) {
				
			}
			else if(ae.getSource() == jmiSave) {
				String path = fileframe.getSaveLocation();
				scheduler.save(path);
			}
			else if(ae.getSource() == jmiQuit) {
				System.exit(0);
			}
			else if(ae.getSource() == jmiConnect) {
				
			}
			else if(ae.getSource() == jmiOptions) {
				OptionsFrame options = new OptionsFrame();
			}
			else if(ae.getSource() == jmiGenerate) {
				scheduler.generate();
			}
			else if(ae.getSource() == jmiNewSchedule) {
				scheduler.newSchedule();
			}
			else if(ae.getSource() == jmiLoad) {
				String path = fileframe.getOpenLocation();
				scheduler.load(path);
			}
		}
		
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
